package zone.haiwen.demo.controller;

import zone.haiwen.demo.service.MyOperationService;
import zone.haiwen.demo.util.JsonResult;
import zone.haiwen.demo.util.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Description: 前端控制器
 * @author zhangHaiWen
 * @data 2021/7/7 19:50
 * @return
 **/

@RestController
@RequestMapping("/test/myOperation")
public class MyOperationController {
    @Autowired
    private MyOperationService myOperationService;

    @GetMapping("/arithmetic")
    public JsonResult arithmetic(String input) {
       String result = this.myOperationService.arithmeticOperation(input);
       return new JsonResult(ResultCode.SUCCESS, result);
    }

    @GetMapping("/maxInt")
    public JsonResult maxInt(@RequestParam(value = "args", required = false) List<Integer> args) {
       int result = this.myOperationService.maxInt(args);
       return new JsonResult(ResultCode.SUCCESS, result);
    }

    @GetMapping("/sum")
    public JsonResult sum(@RequestParam(value = "args", required = false) List<Integer> args) {
        int result = this.myOperationService.sumInt(args);
        return new JsonResult(ResultCode.SUCCESS, result);
    }

    @GetMapping("/getDate")
    public JsonResult getDate() {
        String date = this.myOperationService.getDate();
        return new JsonResult(ResultCode.SUCCESS, date);
    }

}
